<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<{include file='backend/lib/meta.html'}>
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/verydows.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/main.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/poper.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/shipping.css" />
<script type="text/javascript" src="public/script/jquery.js"></script>
<script type="text/javascript" src="public/theme/backend/js/verydows.js"></script>
<script type="text/javascript" src="public/theme/backend/js/shipping.js"></script>
<script type="text/javascript">
function submitForm(){
  $('#name').vdsFieldChecker({rules:{required:[true, '名称不能为空'], maxlen:[60, '名称不能超过60个字符']}});
  $('#scopebtn').vdsFieldChecker({rules:{scope:[$('#scopeli dl').size() > 0, '至少添加一个配送范围']}});
  $('#seq').vdsFieldChecker({rules:{seq:[true, '排序只能填写0到99的整数']}});
  var scope = {};
  $('#scopeli dl').each(function(i, e){
    scope[i] = $(e).data('params');
  });
  $('#params').val(JSON.stringify(scope));
  $('#spform').vdsFormChecker();
}
</script>
</head>
<body>
<{if $_GET['a'] == 'add'}>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>新增配送方式</h2></div>
  <form method="post" action="<{url m=$MOD c='shipping_method' a='add' step='submit'}>" id="spform">
    <input type="hidden" name="params" id="params" />
    <div class="box">
      <div class="module">
        <table class="dataform">
          <tr>
            <th width="110">名称</th>
            <td><input class="w200 txt" name="name" id="name" type="text" /></td>
          </tr>
          <tr>
            <th>配送范围</th>
            <td>
              <p class="pad5"><button type="button" class="cbtn sm btn" id="scopebtn" onclick="popScope()">+1 配送区域</button></p>
              <div class="scopeli" id="scopeli"></div>
            </td>
          </tr>
          <tr>
            <th>使用说明</th>
            <td>
              <textarea class="txtarea" name="instruction" id="instruction" cols="68" rows="5"></textarea>
              <p class="c999 mt10">"使用说明" 将会在用户下单页面选择配送方式时显示</p>
            </td>
          </tr>
          <tr>
            <th>排序</th>
            <td><input class="w50 txt" name="seq" id="seq" value="99" type="text" /></td>
          </tr>
          <tr>
            <th>状态</th>
            <td>
              <p class="pad5">
                <label class="green"><input type="radio" name="enable" value="1" checked="checked" /><font class="ml5">启用</font></label>
                <label class="red ml20"><input type="radio" name="enable" value="0" /><font class="ml5">关闭</font></label>
              </p>
            </td>
          </tr>
        </table>
      </div>
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并提交</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{else}>
<script type="text/javascript">
$(function(){
  var scopetpl = $('#scoperow-tpl').html(), html = '';
  $.each($('#scopeli').data('params'), function(i, p) {
    var area_str = '', charge_str = '';
    if(typeof(p.area) == 'object'){
      $.each(p.area, function(i, a) {
        area_str += '<font>'+$('#areasel input[value='+a+']').next().text()+'</font>';
      });
    }else{
      area_str = '<font>全国范围</font>';
      $('#scopebtn').prop('disabled',true).addClass('disabled');
    }
    $('#charge-'+p.type).find('input').each(function(i, c){
      charge_str += '<span>'+$(c).prev().text()+'<font>'+p[$(c).data('key')]+'</font>'+$(c).next().text()+'</span>';
    });
    html = scopetpl.replace('{$area}', area_str).replace('{$charge}', charge_str);
    $(html).data('params', p).appendTo('#scopeli');
  });
});
</script>
<div class="content">
  <div class="loc">
    <h2><i class="icon"></i>编辑配送方式</h2>
  </div>
  <form method="post" action="<{url m=$MOD c='shipping_method' a='edit' id=$rs.id step='submit'}>" id="spform">
    <input type="hidden" name="params" id="params" />
    <div class="box">
      <div class="module">
        <table class="dataform">
          <tr>
            <th width="110">名称</th>
            <td><input class="w200 txt" name="name" id="name" type="text" value="<{$rs.name}>" /></td>
          </tr>
          <tr>
            <th>配送范围</th>
            <td>
              <p class="pad5"><button type="button" class="cbtn sm btn" id="scopebtn" onclick="popScope()">+1 配送区域</button></p>
              <div class="scopeli" id="scopeli" data-params='<{$rs.params nofilter}>'></div>
            </td>
          </tr>
          <tr>
            <th>使用说明</th>
            <td>
              <textarea class="txtarea" name="instruction" id="instruction" cols="68" rows="5"><{$rs.instruction}></textarea>
              <p class="c999 mt10">"使用说明" 将会在用户下单页面选择配送方式时显示</p>
            </td>
          </tr>
          <tr>
            <th>排序</th>
            <td><input class="w50 txt" name="seq" id="seq" type="text" value="<{$rs.seq}>" /></td>
          </tr>
          <tr>
            <th>状态</th>
            <td>
              <p class="pad5">
                <label class="green"><input type="radio" name="enable" value="1" <{if $rs.enable == 1}>checked="checked"<{/if}> /> 启用</label>
                <label class="red ml20"><input type="radio" name="enable" value="0" <{if $rs.enable == 0}>checked="checked"<{/if}> /> 关闭</label>
              </p>
            </td>
          </tr>
        </table>
      </div>
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并更新</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{/if}>
<{include file='backend/shipping/ship_scope.html'}>
</body>
</html>